
import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart';
import '../../constants.dart';
import '../http/base_dio.dart';
import 'dart:io';
part 'material_api.g.dart';

@RestApi(baseUrl: kBaseUrl)
abstract class MaterialApi {
  factory MaterialApi({Dio dio, String baseUrl}) {
    dio ??= BaseDio.getInstance().getDio();
    return _MaterialApi(dio, baseUrl: baseUrl);
  }

  @GET("/api/v1/edupartnerfileinfo") //拉取图片列表
  Future<FileListResponse> fileList(@Query("pId") int pId,
      @Query("pageIndex") int page, @Query("pageSize") int size);


  @GET("/api/v1/edupartnerfiledir") //获取目录
  Future<FileDirResponse> getDir(@Query("typeGroup") String typeGroup,@Query("pId") int pId);

  @POST("/api/v1/edupartnerfiledir") //创建目录
  Future<CreateDirResponse> createDir(@Body() DirRequestBody body);

  @PUT("/api/v1/edupartnerfiledir/{id}") //修改目录
  Future<CreateDirResponse> modifyDir(@Path("id") int id,@Body() DirRequestBody body);

  @DELETE("/api/v1/edupartnerfiledir") //删除目录
  Future<CreateDirResponse> deleteDir(@Body() DirDelRequestBody body);

  @POST("/api/v1/uploadfile/partnerpictures") //上传文件
  Future<UploadResponse> upload(@Part(value: "type") int type, @Part(value: "typeGroup") String typeGroup,
      @Part(value: "pId") int pId, @Part(value: "file") File file);
}

@JsonSerializable()
class FileDirResponse extends Object {
  int code;
  String msg;
  List<FileDirBean> data;
  String requestId;

  FileDirResponse({this.code, this.msg, this.data, this.requestId});
  factory FileDirResponse.fromJson(Map<String, dynamic> srcJson) => _$FileDirResponseFromJson(srcJson);
}

@JsonSerializable()
class FileDirBean {

  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'label')
  String label;

  @JsonKey(name: 'pId')
  int pId=0;

  @JsonKey(name: 'partnerId')
  int partnerId;

  @JsonKey(name: 'sort')
  int sort;

  @JsonKey(name: 'path')
  String path;

  @JsonKey(name: 'typeGroup')
  String typeGroup;

  @JsonKey(name: 'createBy')
  int createBy;

  @JsonKey(name: 'updateBy')
  int updateBy;

  @JsonKey(name: 'createdAt')
  String createdAt;

  @JsonKey(name: 'updatedAt')
  String updatedAt;

  @JsonKey(name: 'children')
  List<FileDirBean> children;

  FileDirBean(this.id,this.label,this.pId,this.partnerId,this.sort,this.path,this.typeGroup,this.createBy,this.updateBy,this.createdAt,this.updatedAt,this.children,);
  //
  factory FileDirBean.fromJson(Map<String, dynamic> srcJson) => _$FileDirBeanFromJson(srcJson);
  //
  Map<String, dynamic> toJson() => _$FileDirBeanToJson(this);
}

@JsonSerializable()
class DirRequestBody {
  int pId; //
  int id;
  String typeGroup; //
  String label; //

  DirRequestBody({this.pId, this.label,this.typeGroup,this.id});

  Map<String, dynamic> toJson() => _$DirRequestBodyToJson(this);
}
@JsonSerializable()
class DirDelRequestBody {
  List<int> ids;
  DirDelRequestBody(this.ids);

  Map<String, dynamic> toJson() => _$DirDelRequestBodyToJson(this);
}
@JsonSerializable()
class CreateDirResponse {

  String requestId;
  int code;
  String msg;

  CreateDirResponse({this.code,this.msg,this.requestId});

  factory CreateDirResponse.fromJson(Map<String, dynamic> json) =>
      _$CreateDirResponseFromJson(json);
}
@JsonSerializable()
class UploadResponse {
  String requestId;
  int code;
  String msg;

  UploadResponse({this.code,this.msg,this.requestId});


  factory UploadResponse.fromJson(Map<String, dynamic> json) =>
      _$UploadResponseFromJson(json);
}

@JsonSerializable()
class UploadBody {
  String file;
  int  pId;
  //资源类型 	固定为1即可
  int type=1;
  //横构图、竖构图、年份等信息 非必传
  String attrMark;

  UploadBody(this.pId, this.type, this.attrMark,this.file);
}




@JsonSerializable()
class FileListResponse extends Object {

  @JsonKey(name: 'requestId')
  String requestId;

  @JsonKey(name: 'code')
  int code;

  @JsonKey(name: 'msg')
  String msg;

  @JsonKey(name: 'data')
  FileData data;

  FileListResponse(this.requestId,this.code,this.msg,this.data,);

  factory FileListResponse.fromJson(Map<String, dynamic> srcJson) => _$FileListResponseFromJson(srcJson);

  Map<String, dynamic> toJson() => _$FileListResponseToJson(this);

}


@JsonSerializable()
class FileData extends Object {

  @JsonKey(name: 'count')
  int count;

  @JsonKey(name: 'pageIndex')
  int pageIndex;

  @JsonKey(name: 'pageSize')
  int pageSize;

  @JsonKey(name: 'list')
  List<FileEntity> list;

  FileData(this.count,this.pageIndex,this.pageSize,this.list,);

  factory FileData.fromJson(Map<String, dynamic> srcJson) => _$FileDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$FileDataToJson(this);

}


@JsonSerializable()
class FileEntity extends Object {

  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'type')
  String type;

  @JsonKey(name: 'name')
  String name;

  @JsonKey(name: 'size')
  String size;

  @JsonKey(name: 'pId')
  int pId;

  @JsonKey(name: 'urlThumb')
  String urlThumb;

  @JsonKey(name: 'urlSource')
  String urlSource;

  @JsonKey(name: 'urlMiddle')
  String urlMiddle;

  @JsonKey(name: 'path')
  String path;

  @JsonKey(name: 'plateType')
  String plateType;

  @JsonKey(name: 'mark')
  String mark;

  @JsonKey(name: 'status')
  String status;

  @JsonKey(name: 'source')
  String source;

  @JsonKey(name: 'ext')
  String ext;

  @JsonKey(name: 'checkCode')
  String checkCode;

  @JsonKey(name: 'typeGroup')
  String typeGroup;

  @JsonKey(name: 'createBy')
  int createBy;

  @JsonKey(name: 'updateBy')
  int updateBy;

  @JsonKey(name: 'createdAt')
  String createdAt;

  @JsonKey(name: 'updatedAt')
  String updatedAt;

  FileEntity(this.id,this.type,this.name,this.size,this.pId,this.urlThumb,this.urlSource,this.urlMiddle,this.path,this.plateType,this.mark,this.status,this.source,this.ext,this.checkCode,this.typeGroup,this.createBy,this.updateBy,this.createdAt,this.updatedAt,);

  factory FileEntity.fromJson(Map<String, dynamic> srcJson) => _$FileEntityFromJson(srcJson);

  Map<String, dynamic> toJson() => _$FileEntityToJson(this);

}



